//
//  MyHeaderView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/12.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "MyHeaderView.h"
@interface MyHeaderView()

// 名字
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

// 头像
@property (weak, nonatomic) IBOutlet UIImageView *iconImage;

@property (weak, nonatomic) IBOutlet UIButton *qiehuanBtn;

// 标志
@property (weak, nonatomic) IBOutlet UILabel *identityLabel;

// 门店名称
@property (weak, nonatomic) IBOutlet UILabel *companyName;

@property (weak, nonatomic) IBOutlet UIView *backGroundView;

/** 尺寸 */
@property (nonatomic, assign) CGSize identityStrSize;

/** <#desc#> */
@property (nonatomic, assign) CGFloat width;
@end

@implementation MyHeaderView
//@synthesize mDelegate;
- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.backgroundColor = CommonColor;
    
    UIImage *img1=[UIImage imageNamed:@"arrow_right"];
    UIImage *tinted1 = [img1 rt_tintedImageWithColor:[UIColor whiteColor]];
    [self.qiehuanBtn setImage:tinted1 forState:UIControlStateNormal];
    
    
    // 设置头像
    self.backGroundView.backgroundColor = [UIColor colorWithHexString:@"cccccc" alpha:0.24];
    self.backGroundView.layer.cornerRadius = self.backGroundView.width * 0.5;
    self.backGroundView.layer.masksToBounds = YES;
    self.iconImage.layer.masksToBounds = YES;
    self.iconImage.layer.cornerRadius = self.iconImage.width *0.5;
    self.iconImage.contentMode = UIViewContentModeScaleToFill;
    self.iconImage.layer.borderColor = [UIColor whiteColor].CGColor;
    self.iconImage.layer.borderWidth = 0;
}

// 修改个人信息
- (IBAction)modiflyPorfile:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(personalDetailsBtnClick:)]) {
        [self.delegate personalDetailsBtnClick:sender];
    }
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

+ (instancetype)myHeaderView{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
}

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    
    // 设置头像
    NSString *urlStr = [[dict objectForKey:@"userData"] objectForKey:@"headImageUrl"];// objectForKey:@"headImage"];
    NSURL *url = [NSURL URLWithString:urlStr];
    [self.iconImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"touxiang_normal"]];
    
    // 名字
    NSString *nameT = [[dict objectForKey:@"userData"] objectForKey:@"userName"];
    if (nameT.length >12) {
        NSString *subStr = [nameT substringToIndex:12];
        self.nameLabel.text = [NSString stringWithFormat:@"%@···",subStr];
    } else{
        self.nameLabel.text = nameT;
    }
    
    // 设置公司名称
    self.companyName.text = [[dict objectForKey:@"userData"] objectForKey:@"groupName"];
    
    // 店员类型
    NSString *identityStr = [[dict objectForKey:@"userData"] objectForKey:@"roleName"];
    CGSize identityStrSize = [identityStr boundingRectWithSize:CGSizeMake(ScreenWidth, 2000.f) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0]} context:nil].size;
    self.identityStrSize = identityStrSize;
    [self.identityLabel sizeToFit];
    self.width = identityStrSize.width;
    self.identityLabel.textAlignment = NSTextAlignmentCenter;
    self.identityLabel.font = [UIFont systemFontOfSize:12.0];
    self.identityLabel.text = identityStr;

 
    self.identityLabel.backgroundColor = [UIColor colorWithRed:228/255.0 green:182/255.0 blue:42/255.0 alpha:1.0];// [UIColor colorWithHexString:@"fb5e2c"];
    self.identityLabel.textColor = [UIColor whiteColor];
    
}
//
- (void)layoutSubviews{
    [super layoutSubviews];
    self.identityLabel.width = self.width +8;

}
@end
